package com.jiepu.daily.corejava.advanceed.part6thread;

import org.jetbrains.annotations.NotNull;

/**
 * @Description:
 * @author: xinjie.txt
 * @date: 2020/8/3  8:37
 */
public class ConcurrentDemo4 {

	static class MyArrayList {
		Object[] data = new Object[200];
		int size;

		public synchronized void add(@NotNull Object o) {
			synchronized (o) {
				data[size++] = o;
			}
		}

	} // MyArrayList



	public static void main(String[] args) {
		MyArrayList list1 = new MyArrayList();
		MyArrayList list2 = new MyArrayList();


		Thread t1 = new Thread(){
			@Override
			public void run() {
				for (int i = 0; i <100 ; i++) {
					list1.add(new Object());
				}

			}
		};
		Thread t2 = new Thread(){
			@Override
			public void run() {
				for (int i = 0; i <100 ; i++) {
					list2.add(new Object());
				}
			}
		};

	}


}
